package StudyCode.summary.myfile;

import java.io.File;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SearchDirByFileName {
	public static void main(String[] argv) throws Exception {
		String path = "E:\\Copy";
		String target = "1.txt";
		searchDir(path, target);
	}

	private static void searchDir(String path, String target) {
		File f = new File(path);
		if (f.isDirectory()) {
			File[] fileArray = f.listFiles();
			if (fileArray != null) {
				for (File file : fileArray) {
					searchDir(file.getPath(), target);
				}
			}
		} else {
			if (f.getName().contains(target)) {
				System.out.println("文件 " + target + " 搜索到，路径是: " + f);
			}
		}
	}
}
